home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1 Issue 2 / PDCD-1 - Issue 02.iso / _printapps / printapps / _columns / !COLUMNS / EXAMPLES / EXAMPLE
Text File  |  1993-08-13  |  17KB  |  411 lines

  1. ArcDraw File Format
  2. ===================
  3.  
  4. Version Number: 1.07
  5.  
  6. Introduction
  7. ------------
  8.  
  9. The ArcDraw file format provides an object-oriented description of a graphic
  10. image. It represents an object in its editable form, unlike a
  11. page-description language such as PostScript which simply describes an
  12. image. This document describes the file format, and the rules that should be
  13. used in order to render the object on a display device.
  14.  
  15. Parties wishing to define their own object types should use the same
  16. approach as for the allocation of SWI numbers [Reference: Arthur/RISC OS
  17. Programmer's Reference Manual].
  18.  
  19. Coordinates
  20. -----------
  21.  
  22. All coordinates within an ArcDraw file are signed 32-bit integers that give
  23. absolute positions on a large image plane. The units are 1/(180*256) inches,
  24. or 1/640 of a printer's point. When plotting on an Archimedes screen, an
  25. assumption is made that one OS-unit on the screen is 1/180 of an inch.
  26. This gives an image reaching over half a mile in each direction from the
  27. origin. The actual image size (e.g. the page format) is not defined by the
  28. file, though the maximum extent of the objects defined is quite easy to
  29. calculate. Positive-x is to the right, Positive-y is up. The printed page
  30. conventionally has the origin at its bottom left hand corner. When
  31. rendering the image on a raster device, the origin is at the bottom
  32. left hand corner of a device pixel.
  33.  
  34. Colours
  35. -------
  36.  
  37. Colours are specified in ArcDraw files as absolute RGB values in a
  38. 32-bit word. The format is:
  39.   byte 0: reserved (must be zero)
  40.   byte 1: unsigned red value
  41.   byte 2: unsigned green value
  42.   byte 3: unsigned blue value
  43.  
  44. For colour values, 0 means none of that colour and 255 means
  45. fully saturated in that colour.
  46.  
  47. (Aside: the phrase "reserved and must be zero" means:
  48.     when creating such an object, set to zero
  49.     when reading such an object, do NOT assume that these fields are zero
  50. This allows the fields to be used for future expansion. End aside.)
  51.  
  52. The bytes in a word of an ArcDraw file are in little-endian order,
  53. e.g. the lest significant byte appears first in the file.
  54.  
  55. The special value &FFFFFFFF is used in the filling of areas and outlines to
  56. mean "transparent".
  57.  
  58. The File Header
  59. ---------------
  60.  
  61. The file consists of a header, followed by a sequence of objects.
  62.  
  63. The file header is of the following form.
  64.   1-byte ASCII 'D'
  65.   1-byte ASCII 'r'
  66.   1-byte ASCII 'a'
  67.   1-byte ASCII 'w'
  68.   1-word major format version stamp - currently 201 (decimal)
  69.   1-word minor format version stamp - currently 0
  70.   12-byte identity of the program that produced this file.
  71.     typically 8 ASCII chars, padded with spaces.
  72.   4-word bounding box: low x, low y, high x, high y
  73.  
  74. When rendering an ArcDraw file, check the major version number. If this is
  75. greater than the latest version you recognise then refuse to render the file
  76. (e.g. generate an error message for the user), as an incompatible change in
  77. the format has occured.
  78.  
  79. The entire file is rendred by rendering the objects one by one, as they
  80. appear in the file.
  81.  
  82. The bounding box indicates the intended image size for this drawing.
  83.  
  84. A Draw file containing a file header but no objects is legal; however,
  85. the bounding box is undefined. In particular the 'x0' value may be
  86. greater than the 'x1' value (and similarly for the y values).
  87. The Object Header
  88. -----------------
  89.  
  90. Each object consists of an object header, followed by a variable amount of
  91. data depending on the object type. the object header is of the following
  92. form:
  93.   1-word object type field
  94.   1-word object size: number of bytes in the object, always a multiple of 4
  95.   4-word object bounding box: low x, low y, high x, high y
  96.  
  97. The bounding box describes the maximum extent of the rendition of the
  98. object: the object cannot affect the appearance of the display outside this
  99. rectangle. The upper coordinates are an outer bound, in that the device
  100. pixel at (x-low, y-low) may be affected by the object, but the one at
  101. (x-high, y-high) may not be. The rendition procedure may use clipping on
  102. these rectangles to abandon obviously invisible objects.
  103.  
  104. Objects with no direct effect on the rendition of the file have no
  105. bounding box: these will be identified explicitly in the object descriptions
  106. that follow.
  107.  
  108. If an unidientified object type field is encountered when rendering a file,
  109. ignore the object and contine.
  110.  
  111. The object size field includes the object header.
  112.  
  113. The rest of the data for and object depends on the object type field.
  114.  
  115. The Font Table object
  116. ---------------------
  117.  
  118. This object is somewhat special in that only one of it ever appears in
  119. an ArcDraw file. It has no direct effect on the appearance of the image,
  120. but maps font numbers (used in text objects) to textual names of fonts.
  121. It must precede all Text objects.
  122.  
  123. A Font Table object has no bounding box in its object header.
  124.  
  125.   object type number: 0
  126.   object data:
  127.     sequence of font number definitions
  128.     up to 3 zero characters, to pad to word boundary
  129.  
  130.   a font number definition consists of:
  131.     1 character font number (non-zero)
  132.     textual name of corresponding font (characters within 32..126)
  133.     zero character
  134.  
  135. Comparison of font names is case-insensitive.
  136.  
  137. Text objects
  138. ------------
  139.   object type number: 1
  140.   object data:
  141.     1-word text colour
  142.     1-word text background colour hint
  143.     1-word text style
  144.     1-word x unsigned nominal size of the font
  145.     1-word y unsigned nominal size of the font
  146.     2-word x,y coordinates of the start of the text base line
  147.     characters in the string
  148.     zero character
  149.     up to 3 zero characters, to pad to word boundary
  150.  
  151. The character string consists of printing ANSI characters with codes within
  152. 32..126 or 128..255. This need not be checked during rendering, but other
  153. codes may produce undefined or system-dependent results.
  154.  
  155. The style word consists of the following:
  156.   bits 0..7: one byte font number
  157.   bits 8..31: reserved (must be zero)
  158.  
  159. Italic, bold etc. variants are assumed to be distinct fonts.
  160.  
  161. The font number is related to the textual name of a font by a preceding Font
  162. Table object within the file (see below). The exception to this is font number 0,
  163. which is a system font that is sure to be present. When rendering a draw
  164. file, if a font is not recognised, the system font should be used instead.
  165. The system font is monospaced, with the gap between letters equal to the
  166. x nominal size of the font.
  167.  
  168. The background colour hint can be used by font rendition code when
  169. performing anti-aliasing. It is referred to as a hint because it has no
  170. effect on the rendition of the object on a "perfect" printer, nevertheless
  171. for screen rendition it can improve the appearance of text on coloured
  172. backgrounds. The font redition code can assume that the text appears on a
  173. background that matches the background colour hint.
  174.  
  175. Path objects
  176. ------------
  177.   object type number: 2
  178.   object data:
  179.     1-word fill colour (-1 means do not fill)
  180.     1-word outline colour (-1 means no outline)
  181.     1-word outline width (unsigned)
  182.     1-word path style description
  183.     optional dash pattern definition
  184.     sequence of path components.
  185.  
  186. An outline width of 0 means draw the thinnest possible
  187. outline that the device can represent.
  188.  
  189. A path component consists of:
  190.   1-word tag identifier
  191.   sequence of 2-word (x,y) coordinate pairs
  192.  
  193. Each tag identifier word consists of:
  194.   bits 0..7: tag identifier byte
  195.   bits 8..31: reserved, must be zero
  196.  
  197. Possible tag identifier byte values:
  198.   0: end of path: no arguments
  199.   2: move to absolute position: followed by x,y pair
  200.   5: close current sub-path
  201.   8: draw to absolute position: followed by x,y pair
  202.   6: bezier curve through two control points, to absolute position:
  203.      followed by three x,y pairs
  204.  
  205. (Aside: the tag values match the arguments required by the Draw
  206. module. This block of memory can be passed directly to the Draw module for
  207. rendition, see the relevant documentation for precise rules concerning the
  208. appearance of paths. See also manuals on PostScript [Reference: PostScript
  209. Language Reference Manual, Addison-Wesley]).
  210.  
  211. The possible set of legal path components in a path object is described as
  212. follows. A path consists of a sequence of (at least one) subpaths, followed by
  213. an "end of path" path component. A subpath consists of a "move to" path
  214. component, followed by a sequence of (at least one) "draw to" and "bezier
  215. to" path componenets, followed (optionally) by a "close sub-path" path
  216. component.
  217.  
  218. The path style description word is as follows:
  219.  
  220.   bits 0..1: join style:
  221.             0 = mitred joins
  222.             1 = round joins
  223.             2 = bevelled joins
  224.   bits 2..3: end cap style:
  225.             0 = butt caps
  226.             1 = round caps
  227.             2 = projecting square caps
  228.             3 = triangular caps
  229.   bits 4..5: start cap style (same possible values)
  230.   bit 6: winding rule:
  231.             0 = non-zero
  232.             1 = even-odd
  233.   bit 7: dash pattern:
  234.             0 = dash pattern missing
  235.             1 = dash pattern present
  236.   bits 8..15: reserved and must be zero
  237.   bits 16..23: triangle cap width:
  238.             a value within 0..255,
  239.             measured in sixteenths of the line width.
  240.   bits 24..31: triangle cap length:
  241.             a value within 0..255,
  242.             measured in sixteenths of the line width.
  243.  
  244. The mitre cut-off value is the PostScript default (e.g. 10).
  245.  
  246. If the dash pattern is present then it is in the following format:
  247.     1-word  offset distance into the dash pattern to start
  248.     1-word  number of elements in the dash pattern
  249.     for each element of the dash pattern,
  250.       1-word  length of the dash pattern element
  251. The dash pattern is reused cyclically along the length of the path,
  252. with the first element being filled, the next a gap, and so on.
  253.  
  254. Sprite Objects
  255. --------------
  256.   object type number: 5
  257.   object data:
  258.     a sprite
  259.        [Reference: Arthur/RISC OS Programmer's Reference Manual].
  260.  
  261. This contains a pixelmap image. The image is scaled to entirely
  262. fill the bounding box.
  263.  
  264. If the sprite has a palette then this gives absolute values for the
  265. various possible pixels. If the sprite has no palette then colours are
  266. defined locally. Within RISC OS the available "wimp colours" are used.
  267.  
  268. Group Objects
  269. -------------
  270.   object type number: 6
  271.   object data:
  272.     12-byte group object name, padded with spaces.
  273.     a sequence of other objects.
  274.  
  275. The objects contained within the group will have rectangles contained
  276. entirely within the rectangle of the group. Nested grouped objects
  277. are allowed.
  278.  
  279. The object name has no effect on the rendition of the object. It should
  280. consist entirely of printing characters. It may have meaning to specific
  281. editors or programs. It should be preserved when copying objects. If no name
  282. is intended, twelve space characters should be used.
  283.  
  284. Tagged object
  285. -------------
  286.   object type number: 7
  287.   object data:
  288.     1-word tag identifier
  289.     object
  290.     additional data (multiple of 4 in size)
  291.  
  292. To render a Tagged object, simply render the enclosed object. The identifier
  293. and additional data have no effect on the rendition of the object. This allows
  294. specific programs to attatch meaning to certain objects, while keeping the
  295. image renderable.
  296.  
  297. Parties wishing to define their own object tags should use the same approach
  298. as for the allocation of SWI numbers.
  299.  
  300. Text area objects
  301. ---------------
  302.   object type number: 9
  303.   object data:
  304.     1 or more text column objects
  305.     1-word zero, to mark the end of the text columns
  306.     1-word reserved, which must be zero
  307.     1-word reserved, which must be zero
  308.     1-word initial text foreground colour
  309.     1-word initial text background colour hint
  310.     the body of the text column: ASCII characters, terminated by a
  311.       null character.
  312.     0..3 null characters to align to a word boundary.
  313.  
  314. A text area contains a number of text columns. The text area has a body of
  315. text associated with it, which is partioned between the columns. If there
  316. is just one text column object then its bounding box must be exactly
  317. coincident with that of the text area.
  318.  
  319. The body of the text is paginated in the columns. Effects such as font
  320. settings and colour changes are controlled by escape sequences within the
  321. body of the text. All escape sequences start with a backslash character (\);
  322. the escape code is case sensitive, though any arguments is has are not.
  323.  
  324. 1. \! <version><newline or />
  325.    Must appear at the start of the text, and only there. <version> must be 1.
  326. 2. \A<code><optional />
  327.    Set alignment. <code> is one of L (left = default), R (right), C (centre),
  328.    D (double). A change in alignment forces a line break.
  329. 3. \B<R><spaces><G><spaces><B><newline or />
  330.    Set text background colour hint to the given RGB intensity (or the best
  331.    available approximation). Each value is limited to 0..255.
  332. 4. \C<R><spaces><G><spaces><B><newline or />
  333.    Set text foreground colour to the given RGB intensity (or the best
  334.    available approximation). Each value is limited to 0..255.
  335. 5. \D<number><newline or />
  336.    Indicates that the text area is to contain <number> columns. Must appear
  337.    before any printing text.
  338. 6. \F<digit*><name><spaces><size>[<spaces><width>]<newline or />
  339.    Defines a font reference number. <name> is the name of the font, and <size>
  340.    its height. <width> may be omitted, in which case the font width and height
  341.    are the same. Font reference numbers may be reassigned.
  342.    <digit*> is one or two digits.
  343.    <size> and <width> are in points.
  344. 7. \<digit*><optional />
  345.    Selects a font.
  346. 8. \L<leading><newline or />
  347.    Define the leading in points from the end of the (output) line in which the
  348.    \L appears. Default 10 points.
  349. 9. \M<leftmargin><spaces><rightmargin><newline or />
  350.    Defines margins that will be left on either size of the text, from the start
  351.    of the output line in which the sequence appears. The margins are given in
  352.    points, and are limited to values > 0. If the sum of the margins is greater
  353.    than the width of the column, the effects are undefined. Both values default
  354.    to 1 point.
  355. 10. \P<leading><newline or />
  356.     Define the paragraph leading in points. Default 10 points.
  357. 11. \U<position><spaces><thickness><newline or />
  358.    Switch on underlining, at <position> units relative to the character base,
  359.    and of <thickness> units, where a unit is 1/256 of the current font size.
  360.    <position> is limited to -128..+127, and <thickness> to 0..255. To turn
  361.    the underlining off, either give a thickness of 0, or use the command
  362.    \U. (\U followed by a dot).
  363. 12. \V[-]<digit><optional />
  364.     Vertical move by the specified number of points.
  365. 13. \-
  366.     Soft hyphen: if a line cannot be split at a space, a hyphen may be inserted
  367.     at this point instead; otherwise, it has no printing effect.
  368. 14. \<newline>
  369.     Force line break.
  370. 15. \\ appears as \ on the screen
  371. 16 . \;<text><newline>
  372.     Comment: ignored.
  373.  
  374. Other escape sequences are flagged as errors during verification.
  375.  
  376. Lines within a paragraph are split either at a space, or at a soft hyphen,
  377. or (if a single word is longer than a line) at any character.
  378.  
  379. A few other characters have a special interpretation:
  380.  
  381. 1. Control characters are ignored, except for tab, which is replaced by a
  382.    space.
  383. 2. Newlines (that are not part of an escape sequence) are interpreted as
  384.    follows:
  385.    a. occuring before any printing text. A paragraph leading is inserted for
  386.       each newline.
  387.    b. in the body of the text. A single newline is replaced by a space, except
  388.       when it is already followed or preceded by a space or tab. A sequence of
  389.       n newlines inserts a space of (n-1) time the paragraph leading, except
  390.       that paragraph leading at the top of a new text column is ignored.
  391.  
  392. Lines which protrude beyond the limits of the box vertically, e.g. because
  393. the leading is too small are not displayed; however, any font changes, colour
  394. changes, etc. in the text are applied. Characters should not protrude
  395. horizontally beyond the limits of the text column, e.g. due to italic overhang
  396. for this font being greater than the margin setting.
  397.  
  398. Restrictions:
  399. if a chunk of text contains more than 16 colour change sequences, only
  400. the last 16 will be rendered correctly. This is a consequence of the
  401. size of the colour cache used within the font manager. A chunk in this
  402. case means a block of text up to anything that forces a line break,
  403. e.g. the end of a paragraph or a change on the alignment.
  404.  
  405. Text column objects
  406. -----------------
  407.   object type number: 10
  408.   object data: none
  409. A text column object may only occur within a text area object.
  410. Its use is described in the section on text area objects.
  411.